<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="../../common/sessionValidate.jsp" %>
<%@include file="../../common/taglibs.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
  <head>
    <title>T_file_upload信息维护</title>
    <%@ include file="../../common/meta.jsp"%>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
	<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen"  id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <link href="<%= basePath %>images/upload/uploadify.css" rel="stylesheet" type="text/css">

  </head>
  <style>
	hr {
	    margin-top:1px;
	    border-bottom: 1px solid #1BBC9B;
	}
  </style>
  <body>
  <div class="" style="margin-right:2px;padding-right:1px;">
   <!--------------------------部署面板  start------------------------------->
    <!--<form class="form-horizontal form-bordered form-row-strippe" name="form2"  mentod="post" enctype="multipart/form-data">-->
    
    <form action="" class="form-horizontal form-bordered form-row-strippe" name="form2" enctype="multipart/form-data" method="post" >
 	<!-- 查询面板 -->
	<div class="panel panel-primary" id="bsDiv">
	  <!-- Default panel contents -->
	  <div class="panel-heading  " >
      	<i class='icon-filter'></i>&nbsp;上传管理
        <span class="text-right pull-right">
        	<button type="button" class=" btn btn-success btn-xs img-rounded"  onClick="javascript:sc()"><i class="icon-search"></i>&nbsp;上传</button>&nbsp;
            <button type="reset" class=" btn btn-success btn-xs img-rounded"  > <span class="icon-retweet"></span>&nbsp;重置</button>&nbsp;
            <button type="button" class=" btn btn-success btn-xs img-rounded" id="shButton" >&nbsp;<span id="qhDiv" class="icon-chevron-up"></span>&nbsp;</button>
         </span>
	  </div>
	  <div class="panel-body" id="bsDiv" class="panel-collapse collapse in">
	      
	      <div class="col-xs-4 col-sm-4  col-md-4 col-lg-4">
	          <div class="form-group">
	              <label class="control-label col-md-6">文件组</label>
	              <div class="col-md-6">
	       				<select name="filegroup" id="filegroup">
 							<option value="zlxz">资料下载</option>
 							<option value="cyrj">常用软件</option>
 							<option value="bdfh">病毒防护</option>
 						</select>
	              </div>
	          </div>
	      </div>	      
	      <div class="col-xs-4 col-sm-4  col-md-4 col-lg-4">
	          <div class="form-group">
	              <label class="control-label col-md-6">文件名称/描述</label>
	              <div class="col-md-6">
	              	<input name="ext1" id="ext1" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-4 col-sm-4  col-md-4 col-lg-4">
	          <div class="form-group">
	              <label class="control-label col-md-6">文件</label>
	              <div class="col-md-6">
	              	<input name="file1" type="file" id="file1" size="20" class="form-control">
	              </div>
	          </div>
	      </div>	      

	  </div>
	</div>
    </form>
    
    <!--------------------------查询条件表格  start------------------------------->
  	<form class="form-horizontal" name="form1" id="form1">
	<!-- 查询面板 -->
	<div class="panel panel-primary" id="cxDiv">
	  <!-- Default panel contents -->
	  <div class="panel-heading  " >
      	<i class='icon-filter'></i>&nbsp;查询上传内容
        <span class="text-right pull-right">
        	<button type="button" class=" btn btn-success btn-xs img-rounded"  onclick="Search(0)"><i class="icon-search"></i>&nbsp;查询</button>&nbsp;
            <button type="reset" class=" btn btn-success btn-xs img-rounded"  > <span class="icon-retweet"></span>&nbsp;重置</button>&nbsp;
            <button type="button" class=" btn btn-success btn-xs img-rounded" id="shButton" >&nbsp;<span id="qhDiv" class="icon-chevron-up"></span>&nbsp;</button>
         </span>
	  </div>
	  <div class="panel-body" id="shDiv" class="panel-collapse collapse in">
	  	 <div class="col-xs-3 col-sm-3  col-md-3 col-lg-3">
	          <div class="form-group">
	              <label class="control-label col-md-6">id</label>
	              <div class="col-md-6">
	              	<input name="id" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3 col-sm-3  col-md-3 col-lg-3">
	          <div class="form-group">
	              <label class="control-label col-md-6">文件名</label>
	              <div class="col-md-6">
	              	<input name="filename" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3 col-sm-3  col-md-3 col-lg-3">
	          <div class="form-group">
	              <label class="control-label col-md-6">文件类型</label>
	              <div class="col-md-6">
	              	<input name="filetype" type="text" class="form-control">
	              </div>
	          </div>
	      </div>
	      <div class="col-xs-3 col-sm-3  col-md-3 col-lg-3">
	          <div class="form-group">
	              <label class="control-label col-md-6">文件组</label>
	              <div class="col-md-6">
	       				<select name="filegroup" id="filegroup">
	       				    <option value="">全部类型</option>
 							<option value="zlxz">资料下载</option>
 							<option value="cyrj">常用软件</option>
 							<option value="bdfh">病毒防护</option>
 						</select>
	              </div>
	          </div>
	      </div>	      

	  </div>
	</div>
    </form>
    <!--------------------------查询条件表格end------------------------------------->

    <!--------------------------信息列表：带表格面板  start--------------------------------->
	<div class="panel panel-primary">
	  <div class="panel-heading clearfix" >
	  	 <i class='icon-reorder'></i>&nbsp; 数据列表
	  	 <span class="text-right pull-right ">
            <a href="<%=basePath%>t_file_upload/toT_file_uploadCurd?oplx=add" class="text-danger"><i class='icon-plus'></i>&nbsp;新增</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toEdits()" class="text-danger"><i class='icon-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="toViews()"  class="text-danger"><i class='icon-table'></i>&nbsp;查看</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="getDel()" class="text-danger"><i class='icon-minus'></i>&nbsp;删除</a>&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="#" onclick="Search(0)" class="text-danger btn-sm"><i class='icon-refresh'></i>&nbsp;刷新</a>&nbsp;&nbsp;
            <a href="#" onclick="showOrHidden()" class="text-danger btn-sm"><span id="fsDiv" class='glyphicon glyphicon-resize-full'></span></a>
	     </span>
	  </div>
	  <div class="panel-body">
	    <p>每页显示<select id="pageSize" class=" label-primary" onchange="Search(0)">
		  <option value="10" >10</option>
		  <option value="20">20</option>
		  <option value="30">30</option>
		  <option value="50">50</option>
		 </select>条记录，&nbsp;&nbsp;&nbsp;&nbsp;共有记录：<span id="totalCount" class="label label-primary">0</span> 条，总页数：<span id="totalPageNo" class="label label-primary">0</span>页。
        </p>
	    <table id="grid" class="table table-condensed table-striped table-bordered table-hover" class="sortable" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
	     <thead id="grid_head">
	      <tr>
	          <th onclick="" class="table-checkbox" ><input class="group-checkable" name="batchSelectedAll" id="batchSelectedAll" type="checkbox" onclick="selectAll()"></th>
	          <th onclick="sortTableT.sort('grid',0,'String')">文件说明</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">操作人</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">文件组</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">文件名</th>
	          <th style="width:150px">文件路径</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">文件大小(K)</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">插入时间</th>
	          <th onclick="sortTableT.sort('grid',0,'String')">文件类型</th>
	          <th style="width:150px">操作</th>
	      </tr>
	     </thead>
	     <tbody id="grid_body"></tbody>
	    </table>
	    <div class="paging-toolbar">
	   		<ul class="pager" style='margin-bottom:5px;' id='grid_paging'></ul>
	    </div>
	  </div>
    </div>
    <!--------------------------信息列表：带表格面板 end------------------------------------>

  </div>
  </body>
</html>

<script type="text/javascript" src="<%=basePath%>js/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
<script src="<%=basePath%>js/bootstrap.min.js"></script> 
<!--
<script src="<%=basePath%>js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js" ></script>
<script src="<%= basePath %>js/calendar.js" ></script>

<script type="text/javascript">
//新增保存数据
function sc() {
	var ext1 = $("#ext1").val();
	if(ext1==""||ext1==null){
		alert("文件名/描述不能为空！");		
		$("#ext1").focus();
		return false; 
	}
	
	var file1 = $("#file1").val();
	//alert(file1);
	if(file1==""||file1==null){
		alert("文件不能为空！请选择要上传的文件！");		
		$("#file1").focus();
		return false; 
	}
	
	//$("#addSaveButton").attr("disabled", true);
	var url = "<%=basePath%>t_file_upload/uploadOne?userid=<%=request.getSession().getAttribute("FREE_CURRENT_USER")%>&time="+Math.random()
	var a = confirm("您确认上传？");
    if(a==true)
    {
		form2.action =  url;
		form2.submit();
		//$("#addSaveButton").attr("disabled", true);
		//alert("保存完毕！");
    }
}

$().ready(function(){
	//1、初始化数据显示
	Search(0);
	uploadify();
	//2、隐藏或者显示
    $("#shButton").click(function(){
    	$("#shDiv").toggle();
    	$("#qhDiv").toggleClass("icon-chevron-up icon-chevron-down");
  	});

}) //end funciton read;

//根据查询条件，查询列表数据并显示
function Search(startIndex){
	var pageSize = document.getElementById("pageSize").value;
	var condition = $("#form1").serialize();
	var url = "<%=basePath%>t_file_upload/getAllT_file_upload?startIndex="+startIndex+"&pageSize="+pageSize+"&"+condition+"&time="+Math.random();
	//alert(url);
	$.getJSON(url, function (data){
	//$("#pageSize").html(data.pageSize);
	$("#totalCount").html(data.totalCount);
	$("#totalPageNo").html(data.totalPageNo);
	$("#grid_body").html("");

	//1、表格行内容输出
    $.each(data.items, function(i,item){
		var str="<tr>";
		str+="<td><input class='checkboxes' name='batchSelected' id='batchSelected' type='checkbox' value='"+item.id+"'></td>";
		str+="<td>"+doNull(item.ext1)+"</td>";
		str+="<td>"+doNull(item.userid)+"</td>";
		var filegroupname = "未知类型";
		if(item.filegroup!=null&&item.filegroup!=""){
			if(item.filegroup=="zlxz"){
				filegroupname = "资料下载";
			}else if(item.filegroup=="cyrj"){
				filegroupname = "常用软件";
			}else if(item.filegroup=="bdfh"){
				filegroupname = "病毒防护";	
			}
		}
		str+="<td>"+filegroupname+"</td>";
		
		str+="<td>"+doNull(item.filename)+"</td>";
		str+="<td style='width:150px'>"+doSubstring(item.filepath)+"</td>";
		str+="<td>"+doNull(item.filesize/1024)+"</td>";
		str+="<td>"+doZero(item.inserttime)+"</td>";
		str+="<td>"+doNull(item.filetype)+"</td>";
		str+="<td>&nbsp;&nbsp;";
		str+="<a href='<%=basePath%>t_file_upload/toT_file_uploadCurd?oplx=view&id="+item.id+"' class='text-danger'>&nbsp;&nbsp;<span class='glyphicon glyphicon-search' style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
		str+="<a href='<%=basePath%>t_file_upload/toT_file_uploadCurd?oplx=edit&id="+item.id+"' class='text-danger'>&nbsp;&nbsp;<span class='icon-pencil'  style='color:rgb(0, 128, 255)'></span>&nbsp;&nbsp;</a>";
		str+="<a href='javascript:del("+item.id+")' class='text-danger'>&nbsp;&nbsp;<span class='icon-remove' style='color:rgb(0, 128, 255)'></span></a>&nbsp;&nbsp;";
		str+="</td>";
		str+="</tr>";
		$("#grid_body").append(str);
	});//end each data;

	//2、分业处理
	var element = $("#grid_paging");
	if(data.totalCount>0){
		    //第二种处理分页方案，直接生成分页html内容，然后.html()到目标对象；
	        var pageHtml ="";
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.firstIndex+')">首页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.previousIndex+')">上一页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " >当前第  '+data.currentPageNo+' 页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.nextIndex+')">下一页</button></li>';
			pageHtml +='<li><button type="button" class=" btn btn-primary btn-sm " onclick="Search('+data.lastIndex+')">尾页</button></li>';
			element.html(pageHtml);
		}else{
			element.html("");
		}
    })//end getJSON;
}

//通过选择单条记录，点击‘修改‘按钮进行查看
function toEdits(){
   	var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
   	if(id!=false){
		self.location= "<%=basePath%>t_file_upload/toT_file_uploadCurd?oplx=edit&id="+id+"&time="+Math.random();
   	}
}

//通过选择单条记录，点击‘查看‘按钮进行查看
function toViews(){
   	var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
   	if(id!=false){
		self.location= "<%=basePath%>t_file_upload/toT_file_uploadCurd?oplx=view&id="+id+"&time="+Math.random();;
   	}
}

//通过选择单条记录，点击‘删除‘按钮进行查看
function getDel(){
   	var id = checkfunctionIDS(); //如果选择多条记录，则提示请选择一条记录。
   	if(id!=false){
   		del(id);
   	}
}

//删除函数
function del(id){
   	var url = "<%=basePath%>t_file_upload/delT_file_upload?id=" + id+"&time="+Math.random();
 	bootbox.confirm({
		size: 'small',
		buttons: {
	            confirm: {
	                label: ' 删除 ',
	                className: 'btn btn-sm btn-danger'
	            },
	            cancel: {
	                label: '   取消     ',
	                className: 'btn btn-success btn-sm'
	            }
        },
        message: '您确认要删除选中的记录？',
        callback: function(result) {
            if(result) {if(result){ myDel(url);}}
        },
        title:'删除记录提示：',
        className:' '
	})
}
//上传函数
function uploadify(){
	//alert('$("#filegroup").val()='+$("#filegroup").val());
	$("#file_upload").uploadify({
		//校验数据
		'swf' : '<%= basePath %>js/uploadify.swf', //指定上传控件的主体文件，默认‘uploader.swf’
		'uploader' : "<%=basePath%>t_file_upload/uploadList_system?userid=<%=request.getSession().getAttribute("FREE_CURRENT_USER")%>&filegroup="+$("#filegroup").val()+"&time="+Math.random(), 
		'auto' : false, //自动上传
		'multi' : true, //单文件上传
		'buttonImage' : '<%= basePath %>images/upload/uploadify-browse.png',
		'fileTypeExts' : '*.gif; *.jpg; *.png; *.flv; *.avi; *.mp4; *.mp3', //允许上传的文件后缀
		'fileSizeLimit' : '300MB', //上传文件的大小限制，单位为B, KB, MB, 或 GB
		'successTimeout' : 30, //成功等待时间
		'hideButton' : true,
		'simUploadLimit'  : 10,
		'onUploadSuccess' : function(file, data, response) {
			//alert('$("#filegroup").val()111111='+$("#filegroup").val());
			//每成功完成一次文件上传时触发一次
			//var image=eval("["+data+']')[0];
			//$('#url').append("<li><img width=80 src="+image.fileName+" </li>");
			Search(0);
		},
		'onUploadError' : function(file, data, response) {
			//当上传返回错误时触发
			$('#url').append("<li>" + data + "</li>");
		},
		'onUploadStart':function(file){
			//alert('$("#filegroup").val()222222='+$("#filegroup").val());
			var element = {};
			element.one = $("#one").val();
			element.two = $("#two").val();
			element.three = $("#three").val();
			element.four = $("#four").val();
			$('#uploadify').uploadify('settings','formData',element);
		}
	});
};

//上传函数
function uploadifySimple(){
	 
	$("#file_upload").uploadify({
		//校验数据
		'swf' : '<%= basePath %>js/uploadify.swf', //指定上传控件的主体文件，默认‘uploader.swf’
		'uploader' : "<%=basePath%>t_file_upload/commonFileUpload", //指定服务器端上传处理文件，默认‘upload.php’
		'auto' : false, //自动上传
		'multi' : true, //单文件上传
		'buttonImage' : '<%= basePath %>images/upload/uploadify-browse.png',
		'fileTypeExts' : '*.gif; *.jpg; *.png; *.flv; *.avi; *.mp4; *.mp3', //允许上传的文件后缀
		'fileSizeLimit' : '3000MB', //上传文件的大小限制，单位为B, KB, MB, 或 GB
		'successTimeout' : 30, //成功等待时间
		'removeTimeout' : 2, //完成时清除队列显示秒数,默认3秒
		'hideButton' : true,
		'simUploadLimit'  : 10,
		'fileObjName'   : 'file_upload',
		'onUploadSuccess' : function(file, data, response) {
			
		},
		'onUploadError' : function(file, data, response) {
			//当上传返回错误时触发
			alert("上传失败!");
		},
		'onUploadStart':function(file_upload){
			var element = {};
			element.one = $("#file_upload").val();
			//alert("file_upload===="+file_upload);
			//element.two = $("#two").val();
			//element.three = $("#three").val();
			//element.four = $("#four").val();
			$('#uploadify').uploadify('settings','formData',element);
		}
	});
};
</script>
